package cn.fl.repay.service.impl;

import cn.cmm.base.framework.logger.eum.LogExceptionEnum;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.repay.constant.RepayConstant;
import cn.fl.repay.service.IInsOfflineRepayDtlService;
import cn.fl.repay.service.OfflineRepayStrategy;
import cn.fl.repay.vo.InsOfflineRepayDtlVO;
import cn.fl.repay.vo.InsOfflineRepayLogVO;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: leon (lipengd@shiqiao.com)
 * @createDate: 2020/7/1
 * @company: (C) Copyright shiqiao 2020
 * @since: JDK 1.8
 * @description: 亿联银行有特殊的试算和结清规则
 */
@Service
public class YiLianBankOfflineRepayStrategy implements OfflineRepayStrategy {
    private static final Logger logger = LoggerFactory.getLogger(YiLianBankOfflineRepayStrategy.class);

    @Autowired
    private IInsOfflineRepayDtlService insOfflineRepayDtlService;

    @Override
    public boolean support(String repayType) {
        return true;
    }

    @Override
    public List<InsOfflineRepayDtlVO> getRepayDtl(String crCntNo, String repayType, String actPayDt) {
        BaseLogUtils.info(logger, "queryReplayPlan", "还款计划试算queryReplayPlan.DATA,合同号:" + crCntNo + ", 还款时间" + actPayDt, CurrentThreadContext.getCurrentUserName());
        List<InsOfflineRepayDtlVO> repayDtlVOList = null;

        if (repayType.equals(RepayConstant.REPAY_TYP_CD_SETTLE)) {
            repayDtlVOList = insOfflineRepayDtlService.getYiLianBankSettleRepayDtl(crCntNo, actPayDt);
        } else {
            repayDtlVOList = insOfflineRepayDtlService.getYiLianBankStageRepayDtl(crCntNo, actPayDt);
        }
        return repayDtlVOList;
    }

    @Override
    public void checkRepayData(InsOfflineRepayLogVO repayLogVO, List<InsOfflineRepayDtlVO> repayDtlList) {
        BaseLogUtils.newLogger("亿联线下还款暂不校验还款申请数据, RepayLogVO: {}, RepayDtlVOList: {}"
                , JSON.toJSONString(repayLogVO), JSON.toJSONString(repayDtlList)).debug();
    }
}
